package cn.edu.tyu.finance.thingstype.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import cn.edu.tyu.finance.thingstype.domain.Users;
import cn.edu.tyu.finance.util.DbUtil;

/**
 *
 * @author 
 * @version 1.0
 */
public class UserDaoImpl {
	public int addUser(Users users) throws SQLException{
		//��ȡ���ݿ�����
		Connection conn=DbUtil.getConnection();
		//��дsql���
		String sql = "insert into users values(?,?,?)";
		//��ȡԤ��������ִ����
		PreparedStatement ps =conn.prepareStatement(sql);
		//���ò���
		ps.setString(1, users.getUserid());
		ps.setString(2, users.getUsername());
		ps.setString(3, users.getUserpsw());
		//ִ��SQL���,����Ӱ�������
		int res = ps.executeUpdate();
		//�ͷ����ݿ������
		DbUtil.backConn(conn, ps, null);
		return res;
	}
	public static void main(String[] args) throws SQLException {
		UserDaoImpl userDao= new UserDaoImpl();
		Users users = new Users();
		users.setUserid("2");
		users.setUsername("zhl");
		users.setUserpsw("123456");
		int res = userDao.addUser(users);
		System.out.println("res="+res);
	}

}

